package com.four.dailymanage.dish.service;

import com.four.dailymanage.common.bean.Page;
import com.four.dailymanage.dish.dao.PayTotalDao;
import com.four.dailymanage.dish.entity.Dish;
import com.four.dailymanage.dish.entity.PayTotal;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PayTotalService {
    @Autowired
    PayTotalDao payTotalDao;
    //分页形式的查询
    public Page<PayTotal> getPayTotalDish (int pageNum, int pageSize,String startDate,String endDate,String accountName ){
        //计算起始位置
        int start=(pageNum-1)*pageSize;
        //获取分页的数据
        List<PayTotal> list=payTotalDao.getPayTotalByCon(start,pageSize,startDate,endDate,accountName);
        //获取总条目数
        int total=payTotalDao.countPayTotal(startDate, endDate, accountName);
        //计算总页数
        int pages =(total % pageSize == 0 ? total / pageSize : total / pageSize + 1);
        //创建分页对象
        Page<PayTotal> page=new Page<>();
        page.setRecords(list);
        page.setTotal(total);
        page.setPages(pages);
        page.setCurrent(pageNum);
        page.setSize(pageSize);
        return page;
    }


    //批量导出 列表获取 条件查询
    public List<PayTotal> payTotalList(String startDate,String endDate,String accountName){
        return payTotalDao.getPayT(startDate, endDate, accountName);
    }

    //批量导出 行 条件查询
    public  List<PayTotal> payRowsTotal(List<Integer> idsArr){
        if (idsArr==null){
            return null;
        }
        return payTotalDao.getRowsPayT(idsArr);
    }

}
